package com.wwj.feedback.service.impl;

import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.PageObjectUtil;
import com.wwj.common.entitiy.R;
import com.wwj.feedback.constant.ConstantFinal;
import com.wwj.feedback.dao.FeedbackQuestionDao;
import com.wwj.feedback.entitiy.FeedbackQuestionEntity;
import com.wwj.feedback.entitiy.UserEntity;
import com.wwj.feedback.exception.OpenFeignException;
import com.wwj.feedback.feign.UserFeignService;
import com.wwj.feedback.service.FeedbackQuestionService;
import com.wwj.feedback.vo.FeedbackVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class FeedbackQuestionImpl extends ServiceImpl<FeedbackQuestionDao, FeedbackQuestionEntity> implements FeedbackQuestionService {

    @Resource
    private FeedbackQuestionDao feedbackQuestionDao;

    @Resource
    private UserFeignService userFeignService;

    /**
     * 获取未处理的问题数量
     */
    @Override
    public int getNoHandleQuestion() {
        QueryWrapper<FeedbackQuestionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ConstantFinal.FIELD_QUESTION_IDENTIFY, ConstantFinal.VALUE_QUESTION_NO_ANSWER);
        return feedbackQuestionDao.selectCount(queryWrapper);
    }

    /**
     * 获取所有的反馈数据
     */
    @Override
    public PageInfo<FeedbackQuestionEntity> selectAllFeedbackData(String currentPage, String pageSize, String query) {
        Page<FeedbackQuestionEntity> page = PageHelper.startPage(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
        QueryWrapper<FeedbackQuestionEntity> queryWrapper = new QueryWrapper<>();
        if (!query.isEmpty()) {
            // 不为空条件构造
            queryWrapper.like(ConstantFinal.FIELD_QUESTION_ID, query).or()
                    .like(ConstantFinal.FIELD_QUESTION_NUMBER, query).or()
                    .like(ConstantFinal.FIELD_USER_ID, query);
        }
        queryWrapper.orderByDesc(ConstantFinal.FIELD_CREATE_TIME);
        // 查库
        feedbackQuestionDao.selectList(queryWrapper);
        return page.toPageInfo();
    }



}
